<template>
	<view>
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor,textColor]">
				<view class="action" @tap="BackPage" v-if="isBack">
					<text class="icon-back"></text>
					<slot name="backText"></slot>
				</view>
				<view class="action text-xl" v-if="isSetting" @tap="gotoSetting">
					<!-- <text class="icon-back"></text> -->
					<text class="icon-exit"></text>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				curRoute:'',
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var bgImage = this.bgImage;
				var bgStyle = this.bgStyle;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				if (this.bgStyle) {
					style = `${style}${bgStyle}`
				}
				return style
			}
		},
		props: {
			isSetting: {
				type: [Boolean, String],
				default: false
			},
			textColor:{
				type: String,
				default: ''
			},
			bgStyle:{
				type: String,
				default: ''
			},
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		created() {
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			let curRoute = routes[routes.length - 1].route // 获取当前页面路由，也就是最后一个打开的页面路由
			this.curRoute = curRoute;
			console.log("curRoute:",curRoute);
		},
		methods: {
			gotoSetting(){
				uni.reLaunch({
					url: '../../pages/login/login'
				})
			},
			BackPage() {
				if(this.$helper.msgType == 1){
					uni.reLaunch({
						url: '../../pages/menu/menu'
					})
				}else{
					uni.navigateBack({
						delta: 1
					});
				}
			}
		}
	}
</script>

<style>
</style>
